<template>
  <div>
    <el-card>
      <!-- 2.2 表格 -->
      <el-table
        :data="tableData"
        border
        stripe
        style="width: 100%; margin-top: 15px"
      >
        <el-table-column type="index" label="#" width="50" />
        <el-table-column prop="title" label="名称" />
        <el-table-column prop="remarks" label="备注" />
        <el-table-column label="启用状态">
          <template #default="{ row }">
            <el-switch v-model="row.status" active-value="1" inactive-value="0"  />
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template #default="{ row }">
            <el-button type="primary" size="small" @click="handleEdit(row)">同意</el-button>
            <!-- <el-button type="danger" size="small" @click="handleDelete(row)" v-if="row.status == 0">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>

      <!-- 2.3 分页 -->
      <el-pagination
        v-model:currentPage="queryInfo.pageNum"
        v-model:page-size="queryInfo.pageSize"
        :page-sizes="[5, 10, 20, 50]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="getTodoTaskList"
        @current-change="getTodoTaskList"
        style="margin-top: 15px; text-align: right"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { approvalTaskList,approvalTaskdealWith } from '@/request/process/task'


const queryInfo = ref({
  pageNum: 1,
  pageSize: 10,
})
const total = ref(0)

const tableData = ref([])

const getTodoTaskList = async () => {
  const res = await approvalTaskList(queryInfo.value)
    tableData.value = res
    total.value = res.length

}
getTodoTaskList()


function handleEdit(row){
    approvalTaskdealWith({
        taskId: row.taskId,
        result: 1,
        remarks: '同意'
    }).then(res=>{
         getTodoTaskList()
         ElMessage.success('同意成功')
    }).catch(err=>{
        ElMessage.error(err.message)
    })

}

</script>
